package cn.fresh.xuanyuan.module.infra.dal.mysql.column;

import cn.fresh.xuanyuan.framework.common.pojo.PageParam;
import cn.fresh.xuanyuan.framework.common.pojo.PageResult;
import cn.fresh.xuanyuan.framework.mybatis.core.mapper.BaseMapperX;
import cn.fresh.xuanyuan.module.infra.dal.dataobject.column.MallColumnDO;
import cn.fresh.xuanyuan.module.infra.dal.dataobject.column.MallColumnProductDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface MallColumnProductMapper extends BaseMapperX<MallColumnProductDO> {

    default PageResult<MallColumnProductDO> selectPage(Integer columnId, String name, PageParam pageParam) {
        LambdaQueryWrapper<MallColumnProductDO> queryWrapperX = new LambdaQueryWrapper<MallColumnProductDO>()
                .orderByAsc(MallColumnProductDO::getSort);
        queryWrapperX.eq(MallColumnProductDO::getColumnId, columnId);
        queryWrapperX.eq(MallColumnProductDO::getDeleted, false);
        if(StringUtils.isNotBlank(name)) {
            queryWrapperX.like(MallColumnProductDO::getProductName, name.trim());
        }
        return selectPage(pageParam, queryWrapperX);
    }

    default List<MallColumnProductDO> getListBySpuId(Long spuId) {
        LambdaQueryWrapper<MallColumnProductDO> queryWrapperX = new LambdaQueryWrapper<MallColumnProductDO>();
        queryWrapperX.eq(MallColumnProductDO::getProductId, spuId).eq(MallColumnProductDO::getDeleted, false);
        List<MallColumnProductDO> list = selectList(queryWrapperX);
        return list;
    }
}
